<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Holidays extends CI_Controller {

 
	function __construct()
	{
		parent::__construct();
		
		// check if user logged in 
		if (!$this->ion_auth->logged_in())
	  	{
			redirect('auth/login');
	  	}elseif(!$this->ion_auth->is_admin()){
			redirect('auth/login');
		}		
		$this->load->library('form_validation');
		$this->load->model('founder/holiday_model');		
	}

function index()
   {
	   	$data['holidays'] = $this->holiday_model->get_all_holidays();
	  	$meta['page_title']  = 'Holiday List';
		$this->load->view('common/header',$meta);
		$this->load->view('founder/holidays',$data);
		$this->load->view('common/footer');		
   }
   
   function create_holiday()
   {	  
	  $this->form_validation->set_rules('holiday_date','Date','required'); 
	  $this->form_validation->set_rules('holiday_reason', 'Reason', 'required|max_length[50]');
	  
	  if ($this->form_validation->run() == FALSE)
		{
		$data['holidays'] = $this->holiday_model->get_all_holidays();
		$meta['page_title']  = 'Holiday List';
		$this->load->view('common/header',$meta);
		$this->load->view('founder/holidays',$data);
		$this->load->view('common/footer');					
		}
		else
		{	
			$insert= array(
			'date' 		=> $this->input->post('holiday_date'),
			'reason'	 => $this->input->post('holiday_reason')
			);
			//print_r($insert);exit;
			$this->holiday_model->create_holiday($insert);
			$this->session->set_flashdata('holiday_msg', 'Holiday Created Successfully');
			redirect('founder/holidays','refresh');
		}
	  
   }
   
   function delete($delete_id)
   {
	   $query = $this->holiday_model->delete($delete_id);
	   $this->session->set_flashdata('holiday_msg', 'Holiday deleted successfully');
	   redirect('founder/holidays','refresh');
   }
   
  
	
}
	
	?>